// _Test3_VideoSlider.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include "cv.h"
#include "highgui.h"

int g_slider_position=0;
CvCapture* g_capture = NULL;

void onTrackbarSlide(int pos)
{
	// set pointer of current frame to new position
	cvSetCaptureProperty(g_capture,CV_CAP_PROP_POS_FRAMES,pos);
}

int _tmain(int argc, _TCHAR* argv[])
{
	cvNamedWindow("Example3",CV_WINDOW_AUTOSIZE);

	g_capture= cvCreateFileCapture("D:\\MotherEarth.avi");

	int frames = (int)cvGetCaptureProperty(g_capture,CV_CAP_PROP_FRAME_COUNT);

	// create Trackbar, when trackbar event occurs, it will send to function 'void OntrackbarSlide(int)'
	if(frames != 0)
	{
		// create Trackbar name "Position" in window "Example3", by variable g_slider_position
		// with maximum is 'frame'
		cvCreateTrackbar("Position","Example3",&g_slider_position,frames,onTrackbarSlide);
	}

	IplImage* frame;
	while(1)
	{
		frame = cvQueryFrame(g_capture);
		if(!frame)
			break;
		cvShowImage("Example3",frame);

		// Set Track Position, increment 1 to slider position
		cvSetTrackbarPos("Position","Example3",++g_slider_position);

		char c = cvWaitKey(33);
		if(c == 27)
			break;
	}
	cvWaitKey(0);


	// Deallocate
	cvReleaseCapture(&g_capture);
	cvDestroyWindow("Example3");

	return 0;
}



